package com.izocen.rules.assembler.operator;

import com.izocen.rules.assembler.operator.chain.AbstractOperator;
import com.izocen.rules.assembler.operator.chain.unit.CommonOperator;
import com.izocen.rules.assembler.operator.chain.unit.ContainsOperator;
import com.izocen.rules.assembler.operator.chain.unit.InOperator;
import com.izocen.rules.assembler.operator.chain.unit.NotContainsOperator;
import com.izocen.rules.assembler.operator.chain.unit.NotInOperator;
import com.izocen.rules.common.conts.OperatorConts;

public class OperatorChain {
	
	private static OperatorChain oc = new OperatorChain();
	
	private AbstractOperator operator;
	
	private OperatorChain() {
		AbstractOperator equalOperator    = new CommonOperator(OperatorConts.EQUAL);
		AbstractOperator notEqualOperator = new CommonOperator(OperatorConts.NOT_EQUAL);
		AbstractOperator containsOperator = new ContainsOperator(OperatorConts.CONTAINS);
		AbstractOperator notContainsOperator = new NotContainsOperator(OperatorConts.NOT_CONTAINS);
		AbstractOperator inOperator = new InOperator(OperatorConts.IN);
		AbstractOperator gtOperator    = new CommonOperator(OperatorConts.GT);
		AbstractOperator ltOperator    = new CommonOperator(OperatorConts.LT);
		AbstractOperator gteOperator    = new CommonOperator(OperatorConts.GTE);
		AbstractOperator lteOperator    = new CommonOperator(OperatorConts.LTE);
		AbstractOperator notInOperator    = new NotInOperator(OperatorConts.NOT_IN);
		//---------------------构建chain-------------------------//
		equalOperator.setNextOperator(notEqualOperator);
		notEqualOperator.setNextOperator(containsOperator);
		containsOperator.setNextOperator(notContainsOperator);
		notContainsOperator.setNextOperator(inOperator);
		inOperator.setNextOperator(gtOperator);
		gtOperator.setNextOperator(ltOperator);
		ltOperator.setNextOperator(gteOperator);
		gteOperator.setNextOperator(lteOperator);
		lteOperator.setNextOperator(notInOperator);
		this.operator = equalOperator;
	}
	
	public AbstractOperator getOperator() {
		return this.operator;
	}
	
	public static AbstractOperator getChain() {
		return oc.getOperator();
	}

}
